/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.onurkaganaldemir.sample.slice;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.utils.LayoutAlignment;

import com.onurkaganaldemir.ktoastlib.KToast;
import com.onurkaganaldemir.sample.ResourceTable;

/**
 * MainAbilitySlice
 *
 * @since 2021-06-17
 */
public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        findComponentById(ResourceTable.Id_mainBtnSuccess).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                KToast.successToast(getContext(), "This is a success toast.", LayoutAlignment.BOTTOM, KToast.LENGTH_AUTO);
            }
        });

        findComponentById(ResourceTable.Id_mainBtnInfo).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                KToast.infoToast(getContext(), "This is a info toast.", LayoutAlignment.BOTTOM, KToast.LENGTH_AUTO);
            }
        });

        findComponentById(ResourceTable.Id_mainBtnNormal).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                KToast.normalToast(getContext(), "This is a normal toast.", LayoutAlignment.BOTTOM, KToast.LENGTH_AUTO, ResourceTable.Graphic_ic_infinite_white);
            }
        });

        findComponentById(ResourceTable.Id_mainBtnWarning).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                KToast.warningToast(getContext(), "This is a warning toast.", LayoutAlignment.BOTTOM, KToast.LENGTH_AUTO);
            }
        });

        findComponentById(ResourceTable.Id_mainBtnError).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                KToast.errorToast(getContext(), "This is a error toast.", LayoutAlignment.BOTTOM, KToast.LENGTH_AUTO);
            }
        });

        findComponentById(ResourceTable.Id_mainBtnCustomColor).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                KToast.customColorToast(getContext(), "This is a custom color toast.", LayoutAlignment.BOTTOM, KToast.LENGTH_AUTO, ResourceTable.Color_fuchsia, ResourceTable.Graphic_ic_infinite_white);
            }
        });

        findComponentById(ResourceTable.Id_mainBtnCustomDrawable).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                KToast.customBackgroudToast(getContext(), "This is a custom drawable toast.", LayoutAlignment.BOTTOM, KToast.LENGTH_AUTO, ResourceTable.Graphic_background_toast, null, ResourceTable.Graphic_ic_infinite_white);
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
